package net.apexes.demo.codegen.ormlite.column;

import net.apexes.commons.ormlite.Column;
import net.apexes.commons.ormlite.ForeignKey;
import net.apexes.commons.ormlite.Index;
import net.apexes.demo.codegen.ormlite.column.base.QEntityBase;
import net.apexes.demo.codegen.ormlite.entity.Template;

/**
 * QTemplate is a ORMLite query type for Template
 * @see Template
 */
public class QTemplate extends QEntityBase<Template> {

    public static final QTemplate $ = new QTemplate("TEMPLATE");

    public final Column name = field("name").columnName("NAME").varchar(32).notNull().build();

    public final Column description = field("description").columnName("DESCRIPTION").varchar(128).build();

    public final Column dependTemplateId = field("dependTemplateId").columnName("DEPEND_TEMPLATE_ID").varchar(22).build();

    public class Indexs {

        public final Index constraintIndexDf = index("CONSTRAINT_INDEX_DF").column(dependTemplateId).build();

        public final Index primaryKeyDf = index("PRIMARY_KEY_DF").unique().column(id).build();

    }

    public final Indexs ix = new Indexs();

    public class ForeignKeys {

        public final ForeignKey constraintDfe = foreignKey(dependTemplateId, "TEMPLATE", "ID");

    }

    public final ForeignKeys fk = new ForeignKeys();

    public QTemplate(String tableName) {
        super(Template.class, tableName);
    }

    @Override
    public Template newInstance() {
        return new Template();
    }

    @Override
    public Object getFieldValue(Template instance, String fieldName) {
        switch (fieldName) {
            case "name":
                return instance.getName();
            case "description":
                return instance.getDescription();
            case "dependTemplateId":
                return instance.getDependTemplateId();
            default:
                return super.getFieldValue(instance, fieldName);
        }
    }

    @Override
    public void setupFieldValue(Template instance, String fieldName, Object value) {
        switch (fieldName) {
            case "name":
                instance.setName((java.lang.String) value);
                break;
            case "description":
                instance.setDescription((java.lang.String) value);
                break;
            case "dependTemplateId":
                instance.setDependTemplateId((java.lang.String) value);
                break;
            default:
                super.setupFieldValue(instance, fieldName, value);
                break;
        }
    }

}

